<template>
  <el-dialog
     v-drag
    :title="!dataForm.auditId ? '新增' : '修改'"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="dataForm" :inline="true" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
    <el-form-item label="审核用户Id" prop="userId">
      <el-input size="mini"  v-model="dataForm.userId" placeholder="审核用户Id" clearable></el-input>
    </el-form-item>
    <el-form-item label="审核用户名称" prop="userName">
      <el-input size="mini"  v-model="dataForm.userName" placeholder="审核用户名称" clearable></el-input>
    </el-form-item>
    <el-form-item label="需要审核订单的Id" prop="orderId">
      <el-input size="mini"  v-model="dataForm.orderId" placeholder="需要审核订单的Id" clearable></el-input>
    </el-form-item>
    <el-form-item label="需要审核订单的编号" prop="orderNo">
      <el-input size="mini"  v-model="dataForm.orderNo" placeholder="需要审核订单的编号" clearable></el-input>
    </el-form-item>
    <el-form-item label="订单对应的表格名称" prop="tableName">
      <el-input size="mini"  v-model="dataForm.tableName" placeholder="订单对应的表格名称" clearable></el-input>
    </el-form-item>
    <el-form-item label="审核状态（-1不通过，0未审核，1已审核）" prop="auditStatus">
      <el-input size="mini"  v-model="dataForm.auditStatus" placeholder="审核状态（-1不通过，0未审核，1已审核）" clearable></el-input>
    </el-form-item>
    <el-form-item label="标题" prop="title">
      <el-input size="mini"  v-model="dataForm.title" placeholder="标题" clearable></el-input>
    </el-form-item>
    <el-form-item label="门店id" prop="storeId">
      <el-input size="mini"  v-model="dataForm.storeId" placeholder="门店id" clearable></el-input>
    </el-form-item>
    <el-form-item label="门店名称" prop="storeName">
      <el-input size="mini"  v-model="dataForm.storeName" placeholder="门店名称" clearable></el-input>
    </el-form-item>
    <el-form-item label="门店编码" prop="storeCode">
      <el-input size="mini"  v-model="dataForm.storeCode" placeholder="门店编码" clearable></el-input>
    </el-form-item>
    <el-form-item label="创建时间" prop="createTime">
      <el-input size="mini"  v-model="dataForm.createTime" placeholder="创建时间" clearable></el-input>
    </el-form-item>
    <el-form-item label="修改时间" prop="updateTime">
      <el-input size="mini"  v-model="dataForm.updateTime" placeholder="修改时间" clearable></el-input>
    </el-form-item>
    <el-form-item label="创建人" prop="createUsername">
      <el-input size="mini"  v-model="dataForm.createUsername" placeholder="创建人" clearable></el-input>
    </el-form-item>
    <el-form-item label="创建人id" prop="createUserId">
      <el-input size="mini"  v-model="dataForm.createUserId" placeholder="创建人id" clearable></el-input>
    </el-form-item>
    <el-form-item label="修改人" prop="updateUsername">
      <el-input size="mini"  v-model="dataForm.updateUsername" placeholder="修改人" clearable></el-input>
    </el-form-item>
    <el-form-item label="修改人id" prop="updateUserId">
      <el-input size="mini"  v-model="dataForm.updateUserId" placeholder="修改人id" clearable></el-input>
    </el-form-item>
    <el-form-item label="是否可用 1:是" prop="status">
      <el-input size="mini"  v-model="dataForm.status" placeholder="是否可用 1:是" clearable></el-input>
    </el-form-item>
    <el-form-item label="是否删除 1:是" prop="isDeleted">
      <el-input size="mini"  v-model="dataForm.isDeleted" placeholder="是否删除 1:是" clearable></el-input>
    </el-form-item>
    <el-form-item label="备注" prop="remark">
      <el-input size="mini"  v-model="dataForm.remark" placeholder="备注" clearable></el-input>
    </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button size="mini" @click="visible = false">取消</el-button>
      <el-button size="mini" type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  export default {
    data () {
      return {
        visible: false,
        dataForm: {
          auditId: 0,
          userId: '',
          userName: '',
          orderId: '',
          orderNo: '',
          tableName: '',
          auditStatus: '',
          title: '',
          storeId: '',
          storeName: '',
          storeCode: '',
          createTime: '',
          updateTime: '',
          createUsername: '',
          createUserId: '',
          updateUsername: '',
          updateUserId: '',
          status: '',
          isDeleted: '',
          remark: ''
        },
        dataRule: {
          userId: [
            { required: true, message: '审核用户Id不能为空', trigger: 'blur' }
          ],
          userName: [
            { required: true, message: '审核用户名称不能为空', trigger: 'blur' }
          ],
          orderId: [
            { required: true, message: '需要审核订单的Id不能为空', trigger: 'blur' }
          ],
          orderNo: [
            { required: true, message: '需要审核订单的编号不能为空', trigger: 'blur' }
          ],
          tableName: [
            { required: true, message: '订单对应的表格名称不能为空', trigger: 'blur' }
          ],
          auditStatus: [
            { required: true, message: '审核状态（-1不通过，0未审核，1已审核）不能为空', trigger: 'blur' }
          ],
          title: [
            { required: true, message: '标题不能为空', trigger: 'blur' }
          ],
          storeId: [
            { required: true, message: '门店id不能为空', trigger: 'blur' }
          ],
          storeName: [
            { required: true, message: '门店名称不能为空', trigger: 'blur' }
          ],
          storeCode: [
            { required: true, message: '门店编码不能为空', trigger: 'blur' }
          ],
          createTime: [
            { required: true, message: '创建时间不能为空', trigger: 'blur' }
          ],
          updateTime: [
            { required: true, message: '修改时间不能为空', trigger: 'blur' }
          ],
          createUsername: [
            { required: true, message: '创建人不能为空', trigger: 'blur' }
          ],
          createUserId: [
            { required: true, message: '创建人id不能为空', trigger: 'blur' }
          ],
          updateUsername: [
            { required: true, message: '修改人不能为空', trigger: 'blur' }
          ],
          updateUserId: [
            { required: true, message: '修改人id不能为空', trigger: 'blur' }
          ],
          status: [
            { required: true, message: '是否可用 1:是不能为空', trigger: 'blur' }
          ],
          isDeleted: [
            { required: true, message: '是否删除 1:是不能为空', trigger: 'blur' }
          ],
          remark: [
            { required: true, message: '备注不能为空', trigger: 'blur' }
          ]
        }
      }
    },
    methods: {
      init (id) {
        this.dataForm.auditId = id || 0
        this.visible = true
        this.$nextTick(async () => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.auditId) {
            const res = await this.$http({
              url: `/sys/sysaudit/info/${this.dataForm.auditId}`,
              method: 'get',
              params: this.$http.adornParams()
            })
                let data = res.data
                if (data && data.code === 0) {
                    this.dataForm = data.sysAudit
                }
          }
        })
      },
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate(async (valid) => {
          if (valid) {
            const res = await this.$http({
              url:`/sys/sysaudit/${!this.dataForm.auditId ? 'save' : 'update'}`,
              method: 'post',
             data: this.$http.adornData( this.dataForm)
            })
            let data = res.data
            if (data && data.code === 0) {
                this.$message({
                        message: '操作成功',
                        type: 'success',
                        duration: 1500,
                        onClose: () => {
                    this.visible = false
                    this.$emit('refreshDataList')
                }
            })
            } else {
                this.$message.error(data.msg)
            }
          }
        })
      }
    }
  }
</script>
